package com.generation.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author mockingjay
 * @date 2023/4/2 - 20:51
 */
public class PropertiesUtils {

    // 获取配置文件
    private static Properties PROS=new Properties();
    // 配置文件参数
    private static Map<String,String> PROPER_MAP=new ConcurrentHashMap<>();


    static {
        InputStream is=null;
        try {
            is=PropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties");
            PROS.load(is);
            //使用迭代器遍历properties文件
            Iterator<Object> iterator=PROS.keySet().iterator();
            while (iterator.hasNext()){
                String key= (String) iterator.next();
                PROPER_MAP.put(key,PROS.getProperty(key));
            }
        }catch (Exception e){
        }finally {
            if(is!=null){
                try {
                    is.close();
                }catch (IOException e){
                 e.printStackTrace();
                }
            }
        }
    }

    public static String getString(String key){
        return PROPER_MAP.get(key);
    }



}
